﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Security.Principal;
using System.ServiceModel;
using Microsoft.SharePoint;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Navigant.DataContracts;
using Navigant.ServiceInterfaces;

namespace Navigant.UnitTests.WebServices
{
    [TestClass()]
    public class ClientPortalServiceTests
    {
        public TestContext TestContext { get; set; }
        private string portalUrl;

        public ClientPortalServiceTests()
        {
            this.portalUrl = ConfigurationManager.AppSettings["testCaseSite"];
        }

        private class ClientPortalClient : ClientBase<IClientPortalService>, IClientPortalService
        {
            public ClientPortalClient()
            {
                this.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
            }

            #region IClientPortalService Members

            public PortalContract GetPortal(Guid clientPortalId)
            {
                return this.Channel.GetPortal(clientPortalId);
            }

            public List<CaseContract> GetCases(Guid clientPortalId)
            {
                return this.Channel.GetCases(clientPortalId);
            }

            public List<CaseContract> GetCasesByCategory(Guid clientPortalId, string siteDirectoryName, 
                string categoryName, string categoryValue)
            {
                return this.Channel.GetCasesByCategory(clientPortalId, siteDirectoryName, 
                    categoryName, categoryValue);
            }

            public SiteDirectoryCategoriesContract GetSiteDirectoryCategories(Guid clientPortalId, 
                string siteDirectoryName, string categoryName)
            {
                return this.Channel.GetSiteDirectoryCategories(clientPortalId, 
                    siteDirectoryName, categoryName);
            }

            #endregion
        }

        [TestMethod()]
        public void GetAllCasesFromService()
        {
            Guid clientPortalId;
            using (SPSite site = new SPSite(this.portalUrl))
            {
                clientPortalId = site.ID;
            }
            IClientPortalService service = new ClientPortalClient();
            List<CaseContract> cases = service.GetCases(clientPortalId);
            Assert.IsTrue(cases.Count > 0);
        }
    }
}
